﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using BCDto.OA.WorkflowTemplate.WorkflowTemplateStepFormConfig;
using BCTMSRESTful.Configs;
using BCService.Utils;
using BCService.OA.WorkflowTemplate.WorkflowTemplateStepFormConfig;

namespace BCTMSRESTful.Controllers.Management.OA.WorkflowTemplate
{
    /// <summary>
    /// 工作流模板步骤表单配置
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class WorkflowTemplateStepFormConfigController : ManagementBaseController
    {
        private readonly IWorkflowTemplateStepFormConfigService workflowTemplateStepFormConfigService;

        public WorkflowTemplateStepFormConfigController(IWorkflowTemplateStepFormConfigService workflowTemplateStepFormConfigService)
        {
            this.workflowTemplateStepFormConfigService = workflowTemplateStepFormConfigService;
        }

        #region 添加工作流模板步骤表单配置
        /// <summary>
        ///  添加工作流模板步骤表单配置
        /// </summary>
        /// <param name="requestDto">工作流模板步骤表单配置信息</param>
        /// <response code="201">添加工作流模板步骤表单配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加工作流模板步骤表单配置")]
        [ProducesResponseType(typeof(WorkflowTemplateStepFormConfigDto), 201)]
        public IActionResult Post(
            [FromBody] WorkflowTemplateStepFormConfigRequestDto requestDto)
        {
            var result = this.workflowTemplateStepFormConfigService.Add(requestDto,this.Admin);
            return StatusCode((int)HttpStatusCode.Created, result);
        }
        #endregion

        #region 修改工作流模板步骤表单配置
        /// <summary>
        ///  修改工作流模板步骤表单配置
        /// </summary>
        /// <param name="workflowTemplateStepFormConfigId">工作流模板步骤表单配置Id</param>
        /// <param name="putDto">工作流模板步骤表单配置信息</param>
        /// <response code="200">修改工作流模板步骤表单配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{workflow_template_step_form_config_id}")]
        [Log("修改工作流模板步骤表单配置")]
        [ProducesResponseType(typeof(WorkflowTemplateStepFormConfigDto), 200)]
        public IActionResult Put([FromRoute(Name = "workflow_template_step_form_config_id")] long workflowTemplateStepFormConfigId, [FromBody] WorkflowTemplateStepFormConfigPutDto putDto)
        {
            putDto.WorkflowTemplateStepFormConfigId = workflowTemplateStepFormConfigId;
            return StatusCode((int)HttpStatusCode.OK, this.workflowTemplateStepFormConfigService.Update(putDto,this.Admin));
        }
        #endregion

        #region 删除工作流模板步骤表单配置
        /// <summary>
        ///  删除工作流模板步骤表单配置
        /// </summary>
        /// <param name="workflowTemplateStepFormConfigId">工作流模板步骤表单配置Id</param>
        /// <response code="204">删除工作流模板步骤表单配置成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{workflow_template_step_form_config_id}")]
        [Log("删除工作流模板步骤表单配置")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "workflow_template_step_form_config_id")] long workflowTemplateStepFormConfigId)
        {
            this.workflowTemplateStepFormConfigService.Delete(workflowTemplateStepFormConfigId);
            return StatusCode((int)HttpStatusCode.NoContent);
        }
        #endregion

        #region 获取工作流模板步骤表单配置
        /// <summary>
        ///  获取工作流模板步骤表单配置
        /// </summary>
        /// <param name="workflowTemplateStepFormConfigId">工作流模板步骤表单配置Id</param>
        /// <response code="200">获取工作流模板步骤表单配置</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{workflow_template_step_form_config_id}")]
        [ProducesResponseType(typeof(WorkflowTemplateStepFormConfigDto), 200)]
        public IActionResult Get([FromRoute(Name = "workflow_template_step_form_config_id")] long workflowTemplateStepFormConfigId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.workflowTemplateStepFormConfigService.Get(workflowTemplateStepFormConfigId));
        }
        #endregion

        #region 获取工作流模板步骤表单配置列表
        /// <summary>
        ///  获取工作流模板步骤表单配置列表
        /// </summary>
        /// <param name="formCategoryCode">表单分类Code</param>
        /// <response code="200">获取工作流模板步骤表单配置列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]/{form_category_code}")]
        [ProducesResponseType(typeof(WorkflowTemplateStepFormConfigDto), 200)]
        public IActionResult List([FromRoute(Name = "form_category_code")] string formCategoryCode)
        {
            return StatusCode((int)HttpStatusCode.OK, this.workflowTemplateStepFormConfigService.GetList(formCategoryCode));
        }
        #endregion

        #region 获取工作流模板步骤表单配置（分页）
        /// <summary>
        ///  获取工作流模板步骤表单配置（分页）
        /// </summary>
        /// <param name="formCategoryCode">表单分类Code</param>
        /// <param name="formConfigTitle">表单配置标题</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取工作流模板步骤表单配置（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<WorkflowTemplateStepFormConfigDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "form_category_code")] string formCategoryCode,
            [FromQuery(Name = "form_config_title")] string formConfigTitle,
            [FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "sort_name")] string sortName,
            [FromQuery(Name = "ascending")] bool? ascending,
            [FromQuery(Name = "page_index")] int index = 1,
            [FromQuery(Name = "page_size")] int size = 10)
        {
            return StatusCode((int)HttpStatusCode.OK, this.workflowTemplateStepFormConfigService.Query(formCategoryCode, formConfigTitle, start, end, sortName, ascending, index, size));
        }
        #endregion

        #region 获取自定义表单树型列表
        /// <summary>
        /// 获取自定义表单树型列表
        /// </summary>
        /// <response code="200">获取自定义表单树型列表</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(List<object>), 200)]
        public IActionResult TemplateTree()
        {
            return StatusCode((int)HttpStatusCode.OK, this.workflowTemplateStepFormConfigService.TemplateTree());
        }
        #endregion
    }
}

